package org.acme.job.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.acme.job.mapper.SysJobMapper;
import org.acme.job.po.SysJob;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements SysJobService {

    /***
     * 查询掉线节点id列表
     * @param ids
     * @return
     */
    @Override
    public List<Long> getDeathServerId(List<Long> ids) {
        return getBaseMapper().getDeathServerId(ids);
    }

    /****
     * 做serverId节点任务转移
     * @param activeServerIds
     * @param deathServerIds
     */
    @Override
    public void updateJobServerId(List<Long> activeServerIds, List<Long> deathServerIds) {
        for (Long deathServerId : deathServerIds) {
            for (int i = 0; i < activeServerIds.size(); i++) {
                Long activeId = activeServerIds.get(i);
                getBaseMapper().updateJobServerId(deathServerId, activeId, i, activeServerIds.size());
            }
        }
    }


    /****
     * 获取待执行的任务
     * @param serverId
     * @param maxRetrySize 最大的尝试次数
     * @param maxLimitSize 最大的抓取个数
     * @return
     */
    @Override
    public List<SysJob> getJobList(Long serverId, int maxRetrySize, int maxLimitSize) {
        return getBaseMapper().getJobList(serverId, maxRetrySize, maxLimitSize);
    }
}
